<?php
    $this->headTitle('Lịch sử', 'append');
?>
<div class="grid">
    <div class="breadcrumbs">
        <a class="item-1" href="/index">Trang chủ</a> › 
        <a class="item-2" href="/admin/history"><?php $title = $this->headTitle(); if(isset($title[0])) echo $title[0]; ?></a>
        <div class="clear-both"></div>
    </div>
    <div class="search">
        <div class="form">
            <div id="tabs-search">
                <ul class="tabs-menu">
                    <li class="active" id="tabs-1"><span>Tìm kiếm</span></li>
                </ul>
                <div class="tabs tabs-1">
                    <form class="searchHistory" name="fSeachDate" action="/admin/history/index" method="GET">
                        <div class="left">
                            <label>Tài khoản</label>
                            <select class="select" name="userId">
                                <option value="0">Tất cả</option>
                                <?php
                                    if(isset($this->userList)){
                                        foreach($this->userList as $value){
                                            if(isset($this->userId) && $this->userId == $value['userId']){
                                                echo '<option value="',$value['userId'],'" selected="selected">',$value['username'],'</option>';
                                            }else{
                                                echo '<option value="',$value['userId'],'">',$value['username'],'</option>';
                                            }
                                        }
                                    }
                                ?>
                            </select>
                        </div>
                        <div class="right">
                            <label>Tính năng</label>
                            <select class="select" name="mod">
                                <option value="0">Tất cả</option>
                                <?php
                                    if(isset($this->configHistory->alias->controller)){
                                        foreach($this->configHistory->alias->controller as $key=>$value){
                                            if(isset($this->mod) && $this->mod == $key){
                                                echo '<option value="',$key,'" selected="selected">',$value->name,'</option>';
                                            }else{
                                                echo '<option value="',$key,'">',$value->name,'</option>';
                                            }
                                        }
                                    }
                                ?>
                            </select>
                        </div>
                        <div class="clear-both"></div>
                        <div class="datetimeSearch">
                            <div class="left">
                                <label>Game</label>
                                <select multiple="" name="gameS[]" class="select multi">
                                    <option value="">Tất cả</option>
                                    <?php 
                                        foreach($this->gameList as $row){ 
                                            $cls = '';
                                            if(isset($this->gameS) && is_array($this->gameS) && in_array($row['gameId'], $this->gameS)){
                                                $cls = 'selected="selected"';
                                                                                            
                                            }
                                            echo '<option value="',$row['gameId'],'" ',$cls,'>(',$row['gameId'],') ',$row['gameName'],'</option>';
                                        } 
                                    ?>
                                </select>
                            </div>
                            <div class="right">
                                <label>Từ ngày</label>
                                <input type="text" name="startTime" readonly="readonly" value="<?php echo (isset($this->startTime)) ? $this->startTime : '';?>" class="text datepicker3"/>
                                <div class="clear-both" style="margin-top: 10px;"></div>
                                <label>Đến ngày</label>
                                <input type="text" name="endTime" readonly="readonly" value="<?php echo (isset($this->endTime)) ? $this->endTime : '';?>" class="text datepicker3"/>
                            </div>
                        </div>
                        <div class="submit">
                            <input type="submit" name="bntSubmit" value="Tìm" class="loading"/>
                        </div>
                        <div class="clear-both"></div>
                    </form>
                </div>
                <div class="clear-both"></div>
            </div>
            <div class="clear-both"></div>
        </div>
    </div>
    <?php if(count($this->historyList) > 0){ ?>
    <div class="table-full">
        <table border="0" cellspacing="0" cellpadding="0" width="100%">
            <thead>
                <tr>
                    <td class="column">ID</td>
                    <td class="column">Người dùng</td>
                    <td class="column hidden">Module</td>
                    <td class="column">Action</td>
                    <td class="column">Controller</td>
                    <td class="column hidden">Game</td>
                    <td class="column">Obj</td>
                    <td class="column">Thời gian</td>
                    <td class="column" width="20%">url</td>
                    <td class="column">Edit</td>
                </tr>
            </thead>
            <tbody>
                <?php
                    $stt = 1;
                    foreach($this->historyList as $row){
                ?>
                    <tr class="row row-<?php echo $stt;?>">
                        <td class="column text-align-center"><?php echo $row['historyId'];?></td>
                        <td class="column"><span class="blue"><?php echo $row['username'];?></span></td>
                        <td class="column hidden"><?php echo $row['module'];?></td>
                        <td class="column"><?php echo (isset($this->configHistory->alias->action->$row['action']->name)) ? $this->configHistory->alias->action->$row['action']->name : $row['action'];?></td>
                        <td class="column"><?php echo (isset($this->configHistory->alias->controller->$row['controller']->name)) ? $this->configHistory->alias->controller->$row['controller']->name : $row['controller'];?></td>
                        <td class="column hidden"><?php echo (isset($row['obj']) && $row['obj'] == 'game' && isset($row['objId'])) ? $row['objId'] : '';?></td>
                        <td class="column"><?php echo $row['objField'];?></td>
                        <td class="column"><?php echo date("Y-m-d H:i:s",$row['time']);?></td>
                        <td class="column"><a href="<?php echo $row['url'];?>" target="_blank"><?php echo $row['url'];?></a></td>
                        <td class="column text-align-center">
                        <?php 
                            if($row['valueField']){ 
                        ?>
                            <div class="hidden">
                                <div id="historyDetail-<?php echo $row['historyId'];?>" class="historyDetail">
                                    <table border="0" cellspacing="0" cellpadding="0" width="100%">
                                        <tr>
                                            <td colspan="3"><?php echo 'Edit '.$row['obj'].' : '.$row['objField'];?></td>
                                        </tr>
                                        <tr>
                                            <td class="head">Value Name</td>
                                            <td class="head">Value Old</td>
                                            <td class="head">Value New</td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <ul>
                                                <?php
                                                    $valueName = json_decode($row['valueField']);
                                                    if(is_array($valueName)){
                                                        foreach($valueName as $key=>$value){
                                                            echo '<li>',$value,'</li>';
                                                        }
                                                    }else{
                                                        echo '<li>',$valueName,'</li>';
                                                    }
                                                ?>
                                                </ul>
                                            </td>
                                            <td>
                                                <ul>
                                                <?php
                                                    $valueOld = json_decode($row['valueOld']);
                                                    if(is_array($valueOld)){
                                                        foreach($valueOld as $key=>$value){
                                                            echo '<li>',$value,'</li>';
                                                        }
                                                    }else{
                                                        echo '<li>',$valueOld,'</li>';
                                                    }
                                                ?>
                                                </ul>
                                            </td>
                                            <td>
                                                <ul>
                                                <?php
                                                    $valueNew = json_decode($row['valueNew']);
                                                    if(is_array($valueNew)){
                                                        foreach($valueNew as $key=>$value){
                                                            echo '<li>',$value,'</li>';
                                                        }
                                                    }else{
                                                        echo '<li>',$valueNew,'</li>';
                                                    }
                                                ?>
                                                </ul>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                            <a class="fancybox icon icon-view" href="#historyDetail-<?php echo $row['historyId'];?>" title="<?php echo $row['username'].' ngày '.date("Y-m-d H:i:s",$row['time']);?>">
                                <img src="image/icons/icon_search.png" alt="view history" border="0"/>
                            </a>
                        <?php } ?>
                        </td>
                    </tr>
                <?php
                        ++$stt;
                    } 
                ?>
            </tbody>
        </table>
    </div>
    <?php }else{ ?>
    <div class="text-align-center red">Không có dữ liệu</div>
    <?php } ?>
    <div class="pagination">
        <?php 
            if($this->paginator){
                echo $this->paginationControl($this->paginator, 
                        'Sliding' , 'history/pagination.phtml', 
                        array(
                                'userId'=> $this->userId,
                                'mod'   => $this->mod,
                                'startTime' => $this->startTime,
                                'endTime'   => $this->endTime,
                                'gameS'     => $this->gameS
                            )); 
            }
        ?>
    </div>
</div>
<script type="text/javascript" src="/js/fancybox/jquery.mousewheel-3.0.6.pack.js"></script>
<link rel="stylesheet" href="/js/fancybox/jquery.fancybox.css" type="text/css" media="screen" />
<script type="text/javascript" src="/js/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        var bodyWidth = $('body').width()-23;
        if(bodyWidth > 950){
            var marginLeft = (bodyWidth-950)/2;
            $('.table-full').attr('style','z-index: 1;width: '+bodyWidth+'px; margin-left:-'+marginLeft+'px');
        }
        $('.fancybox').fancybox({
            	    width: 600,
                    height: 400,
                    maxHeight: 400,
                    titleShow : true,
                    autoSize	: false,
                    openEffect : 'elastic',
    				openSpeed  : 150,
    				closeEffect : 'elastic',
    				closeSpeed  : 150,
                });
    });
</script>
